function register(){
	class Register{
	        constructor(){
	            // 选择各种元素
	            this.user = document.getElementById("user");
	            this.pass = document.getElementById("pass");
	            this.tel = document.getElementById("tel");
	            this.email = document.getElementById("email");
	            this.submit = document.getElementById("submit");
	            this.msg = document.querySelector(".msg");
	            // 提前准备接口
	            this.url = "http://api.icodeilife.cn:81/user";
	            // 绑定事件
	            this.addEvent()
	        }
	        addEvent(){
	            var that = this;
	            this.submit.onclick = function(){
	                // 注册请求之前获取输入框内容
	                that.u = that.user.value;
	                that.p = that.pass.value;
	                that.t = that.tel.value;
	                that.e = that.email.value;
	                // 开启请求
	                that.load();
	            }
	        }
	        load(){
	            ajax({
	                url:this.url,
	                data:{      // 根据接口文档，发送数据
	                    type: "register",
	                    user: this.u,
	                    pass: this.p,
	                    tel: this.t,
	                    email: this.e
	                }
	            }).then((res)=>{
	                // 请求成功后，查看数据，处理数据
	                // console.log(res);
	                this.res = JSON.parse(res);
	                // 渲染结果
	                this.display();
	            })
	        }
	        display(){
	            // 根据成功或失败，决定后续操作
	            if(this.res.code == 1){
	                this.msg.innerHTML = this.res.msg + "，3秒后到登录页面";
	                setTimeout(()=>{
	                    location.href = "login.html";
	                },3000);
	            }else{
	                this.msg.innerHTML = this.res.msg;
	            }
	        }
	    }
	
	    new Register;
}

function test(){
	var oTel = document.getElementById("tel");
	var oPass = document.getElementById("pass");
	var oMail = document.getElementById("email");
	oTel.onblur = function(){
		var reg = /^[1-3]\d{10}$/;
		if(!reg.test(this.value)){
			this.value = "号码格式不对";
		}
	}
	
	oPass.onblur = function(){
		// 规则：数字、字母
		var reg = /[0-9a-zA-Z]{6,12}$/;
		if(!reg.test(oPass.value)){
			this.value = "密码格式不对";
		}
	}	
	
	oMail.onblur = function(){
		var reg = /^[0-9a-zA-Z]{4,10}@[\da-zA-Z]{2,9}\.[a-zA-Z]{2,4}$/;
		if(!reg.test(this.value)){
			this.value = "请输入正确的电子邮箱";
		}
	}
}